# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def logged_in?
    logged_in = false
    s_user = Session.find_by_token( session[:user] )
    if !s_user.nil?
      user = User.find_by_id( s_user.user_id )
      if !user.nil?
        logged_in = true
      end
    end
    return logged_in
  end

  def current_user
    user_id = Session.find_by_token( session[:user] ).user_id
    user = User.find_by_id(user_id)
    if user.nil? || user.blank?
      user = nil
    end
    return user
  end
  
end
